﻿using Common;
using DevExpress.XtraEditors;
using gregn6Lib;
using NursingFormSystem.Common;
using NursingFormSystem.Model;
using System;
using System.IO;
using System.Windows.Forms;

namespace NursingFormSystem
{
    public partial class BloodGlucPrint : XtraForm
    {
        protected string path = "";
        private GridppReport Report = new GridppReport();       
        public static Tb_User LoginUser;
        public PatientInfoView PatientParams;
        public BloodGlucPrint(int[] id,PatientInfoView PatParams)
        {
            InitializeComponent();
            PatientParams = PatParams;
            string select = @"SELECT '"+ PatientParams.PATIENT_NAME +"' as C1,'"+ PatientParams.AGE +"' as C2,'"+ PatientParams.NURSE_CELL_NAME +"' as C3,'"+ PatientParams.BED_NO +"' as C4,'"+ PatientParams.IN_DEPARTMENT_DATE.ToString("yyyy-MM-dd") +"' as C5,'"+ PatientParams.PATIENT_ID + @"' as C6,* FROM [BNNursingDocsSystem_Develop].[dbo].[t_Bloodsugar_Print](NOLOCK) where ";
            string ids = "'000'";
            if (id.Length == 1)
            {
                select += "BloodsugarId ='" + id[0] + "'";
            }
            else
            {
                for (int i = 0; i < id.Length; i++)
                {
                    ids += ",'" + id[i] + "'";
                }
                select = select + "BloodsugarId in (" + ids + ")";
            }
            select += " order by Date,Time";
                //设置 ShowPrintDlg 属性，让点击工具栏中的打印按钮时不显示打印对话框
                axGRPrintViewer1.ShowPrintDlg = false;
            try
            {
                if (File.Exists(System.Windows.Forms.Application.StartupPath + @"\GRFModel\Ydhl_GRF\血糖检测记录单.grf"))
                {
                    Report.LoadFromFile(System.Windows.Forms.Application.StartupPath + @"\GRFModel\Ydhl_GRF\血糖检测记录单.grf");
                }
                else
                {
                    Report.LoadFromFile(@"../../Ydhl_GRF/血糖检测记录单.grf");  
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("加载临时医嘱表单失败，请检查文件Ydhl_GRF/血糖检测记录单.grf是否存在");
                WriteLog.WriteLogString(ex.Message + ".  加载血糖监测记录表单失败，请检查文件Ydhl_GRF/血糖检测记录单.grf是否存在");
                return;
            }
            Report.ConnectionString = Utility.GetDatabaseConnectionString();
            Report.DetailGrid.Recordset.QuerySQL = select;          
            axGRPrintViewer1.Report = Report;
            axGRPrintViewer1.Start();
        }


        private void Form1_Load(object sender, EventArgs e)
        { 
        
        }
        private void axGRPrintViewer1_CloseButtonClick(object sender, System.EventArgs e)
        {
            Close();
        }

        private void axGRPrintViewer1_CustomButtonClick_1(object sender, Axgregn6Lib._IGRPrintViewerEvents_CustomButtonClickEvent e)
        {
            //响应自定义按钮点击，根据BtnID完成对应的任务
            System.Windows.Forms.MessageBox.Show(System.String.Format("执行自定义按钮任务, BtnID={0}", e.btnID), "CustomButtonClick"
                , System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
        }

        private void axGRPrintViewer1_ToolbarCommandClick(object sender, Axgregn6Lib._IGRPrintViewerEvents_ToolbarCommandClickEvent e)
        { 
        
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            this.Close();
            this.Dispose();
        }

        private void axGRPrintViewer1_Enter(object sender, EventArgs e)
        {

        }
    }
}
